class CustomFormBuilder < ActionView::Helpers::FormBuilder
  #Marks label as required if it has presence validator
  def label(name, options = {})
    begin
      required = ""

      if @object.class.validators_on(name).map(&:class).include? ActiveModel::Validations::PresenceValidator
        required = "&nbsp;<acronym title='Povinná položka' class='required'>*</acronym>"
      end
      
      human_label = I18n.translate("helpers.label.#{@object.class.to_s.downcase}.#{name.to_s.downcase}")
      human_label = human_label.gsub(/ /, "&nbsp;")

      super(name, "#{human_label}#{required}".html_safe, options)
    rescue
      super
    end
  end

  #Turns off text field browser autocompletion
  def text_field(*args)
    options = args.extract_options!
    new_autocomplete = options[:autocomplete] || "off"
    super(*(args << options.merge(:autocomplete => new_autocomplete)))
  end

  #Adds default class to submit button
  def submit(*args)
    options = args.extract_options!
    new_class = options[:class] || "submit_button"
    super(*(args << options.merge(:class => new_class)))
  end
end
